module(...,package.seeall)

require "sprite"

local movementFunctions = {}
local selectedMovement
local data = require "baloonSheet"

local popBalloonSound = audio.loadSound("popBalloon1.mp3")

function createBallon()

	balloonColor = math.random(1,10)
	ballonSpriteData = data.getSpriteSheetData()
	ballonSpriteSheet = sprite.newSpriteSheetFromData("baloonSheet"..balloonColor..".png",ballonSpriteData )
	ballonSpriteSet = sprite.newSpriteSet(ballonSpriteSheet,1,10)

	local ballonSprite = sprite.newSprite(ballonSpriteSet)	
	ballonSprite.y = 200 + math.random()*100
	sprite.add(ballonSpriteSet, "defaultAnim", 1, 7,800)
	sprite.add(ballonSpriteSet, "ballonPop",8,2,10,1)
	ballonSprite:prepare("defaultAnim")
	ballonSprite:play()	
	ballonSprite.YSpeed = -50 - 100*math.random()	
	ballonSprite.movmentParam = math.random()
	ballonSprite.tragetory = math.random(1,4)

	
	ballonSprite.moveBallon = function()		
		
		if (ballonSprite.tragetory == 1) then
			ballonSprite.x = display.contentWidth/2 + 80*ballonSprite.movmentParam*math.sin(ballonSprite.y/100)
		elseif (ballonSprite.tragetory == 2) then
			ballonSprite.x = display.contentWidth/2 + 150*ballonSprite.movmentParam*math.cos(ballonSprite.y/100)
		elseif (ballonSprite.tragetory == 3) then
			ballonSprite.x = display.contentWidth/2 + 10*ballonSprite.movmentParam*math.cos(ballonSprite.y/100)	
		elseif (ballonSprite.tragetory == 4) then
			ballonSprite.x = 500*ballonSprite.movmentParam - 200*ballonSprite.movmentParam*math.sin(ballonSprite.y/90)
		end
	
	end
	
	ballonSprite.moveBallon()
	
	ballonSprite.popBallon = function()
		audio.play(popBalloonSound)
		ballonSprite:prepare("ballonPop")
		ballonSprite:play()	
		jewel = require "Jewel"
		local gem = jewel.createJewel()		
		gem.x = ballonSprite.x
		gem.y = ballonSprite.y
		transition.to(ballonSprite,{delay=200,time=10,alpha=0})	
		return gem
	end
	
	--ballonSprite:setFillColor(0, 0, 255)
	
	return ballonSprite
end



